package com.tfy.liquor.dao;

import com.tfy.liquor.bean.RolloverRecords;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Mapper
@Service
public interface RolloverRecordsDao {

    // 添加数据
    @Insert("insert into rollover_records values(#{id}, #{userId}, #{giveId}, #{orderId}, #{amount}, #{balance}, #{category}, #{illustrate}, #{createDate}, #{remark})")
    int addRolloverRecords(RolloverRecords rolloverRecords);

    // 查询是否有重复数据
    @Select("select count(*) from rollover_records where id=${id} ")
    int getRepeat(String id);

    // 模糊查询转购物券的数据
    @Select("select * from rollover_records where id like '%${id}%' " +
            "or userId like '%${userId}%'" +
            "or giveId like '%${giveId}%'" +
            "or orderId like '%${orderId}%'" +
            "or amount like '%${amount}%'" +
            "or illustrate like '%${illustrate}%'" +
            "or createDate like '%${createDate}%'" +
            "or remark like '%${remark}%'" +
            "order by id desc"
    )
    ArrayList<RolloverRecords> getInfo(String value);

    // 查询数据
    @Select("select * from rollover_records order by id desc")
    ArrayList<RolloverRecords> getRolloverRecords();

    // 根据id查询数据
    @Select("select * from rollover_records where userId=${userId}")
    ArrayList<RolloverRecords> getRolloverRecordsByUserId(String userId);

    // 根据id查询封顶单
    @Select("select * from rollover_records where userId=${userId} and amount >= 6888")
    ArrayList<RolloverRecords> getRolloverByUserId(String userId);

    // 根据日期查询数据
    @Select("select * from rollover_records where Date(createDate)='${date}'")
    ArrayList<RolloverRecords> getRolloverByDate(String date);

    // 根据日期查询封顶单
    @Select("select * from rollover_records where Date(createDate)='${date}' and amount >= 6888")
    ArrayList<RolloverRecords> getOrderByDate(String date);
    // 根据id和日期查询封顶单
    @Select("select * from rollover_records where userId=${userId} and Date(createDate)='${date}' and amount >= 6888")
    ArrayList<RolloverRecords> getOrderByUserIdDate(String userId, String date);

    // 根据id查询封顶单个数
    @Select("select count(*) from rollover_records where userId=${userId} and amount >= 6888")
    int getOrderNumByUserId(String userId);

    // 根据日期查询封顶单个数
    @Select("select count(*) from rollover_records where datetime=date{datetime}=${date} and amount >= 6888")
    int getOrderNumByDate(String date);

    // 查询封顶单个数
    @Select("select count(*) from rollover_records where amount >= 6888")
    int getOrderNum();
}
